package com.share51.novel.common.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

/**
 * 爬虫类型枚举
 * @author gb
 */
@Getter
@AllArgsConstructor
public enum  CrawlTypeEnum {

    /**
     * NOVEL(0,"小说")
     */
    NOVEL(0,"小说"),
    /**
     * CATEGORY(1,"分类")
     */
    CATEGORY(1,"分类")
    ;
    private int code;
    private String name;

    public static CrawlTypeEnum of(int type){
        return Arrays.stream(values())
                .filter(enums->enums.code==type)
                .findAny()
                .orElseThrow(()->new RuntimeException("参数错误，未获取到类型"));
    }

    public static boolean exist(int type){
        return Arrays.stream(values())
                .filter(enums->enums.code==type)
                .findAny()
                .orElse(null)!=null;
    }

}
